/**
 * Created by oneminute on 8/7/14.
 */
var assert = require("assert");
var should = require("should");
var logger = require("../../lib/utils/logger");
var testutils = require("../testutils");
var lz = require("../../lib/utils/modules")();
var httpMocks = require("../lib/http-mock");
var async = require("async");
var route = require("../../routes/route");
var moment = require("moment");


describe("测试/modifyname模块。", function () {

    var express = httpMocks.createExpress();
    var user = null;

    before(function (done) {
        route.setup(express);
        user = new lz.User({
            id: lz.Utils.getUUID("u_"),
            name: "ori_name"
        });
        user.save(function () {
            done();
        });
        //done();
    });

    it("正常修改name属性。", function (done) {
        var request = httpMocks.createExpressRequest({
            method: 'POST',
            url: '/modifyname?uid=' + user.id,
            body: {
                name: "testing_name"
            }
        });
        var response = httpMocks.createExpressResponse();

        express.invoke(request, response, function (_data) {
            var tmpUser = new lz.User({_id: user._id});
            tmpUser.load(function (_err, _user) {
                testutils.check(done, function () {
                    _user.name.should.equal("testing_name");
                });
            });
        });
    });

    it("测试重名的情况。", function (done) {
        var request = httpMocks.createExpressRequest({
            method: 'POST',
            url: '/modifyname?uid=' + user.id,
            body: {
                name: "testing_name"
            }
        });
        var response = httpMocks.createExpressResponse();

        express.invoke(request, response, function (_data) {
            testutils.check(done, function () {
                assert.equal(_data.error, lz.Config.errors.REGISTER_USER_EXISTED.code);
            });
        });
    });

    after(function (done) {
        user.delete(function () {
            done();
        });
    });
});